Completed
Push — master ( a31174...af3b49 )
by Antonio
10s
created

T_IDENTIFIER ➔ ... ➔ this.isEditable   A

Complexity

Conditions 1
Paths 3

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 1
rs 10
c 1
b 0
f 0
cc 1
nc 3
nop 0
1
define(
2
    [
3
        'flagbit/JsonGenerator/Observer'
4
    ],
5
    function(JsonGeneratorObserver) {
6
7
    /**
8
     * @class
9
     * @param {(HTMLElement|HTMLTextAreaElement)} $element
10
     */
11
    var JsonGeneratorInput = function($element) {
12
13
        /**
14
         * @public
15
         * @type {JsonGeneratorObserver}
16
         */
17
        this.observer = new JsonGeneratorObserver();
18
19
20
        /**
21
         * @public
22
         * @param {Object} $data
23
         */
24
        this.write = function($data) {
25
26
            $element.value = JSON.stringify($data);
27
28
            this.observer.notify('write');
29
        };
30
31
32
        /**
33
         * @public
34
         * @returns {Object}
35
         */
36
        this.read = function() {
37
            var $data = {};
0 ignored issues
show
Unused Code introduced by
The assignment to variable $data seems to be never used. Consider removing it.
Loading history...
38
39
            if(this.isEditable()) {
40
                $data = JSON.parse($element.value);
41
            }
42
            else {
43
                $data = JSON.parse($element.innerText);
44
            }
45
46
            return $data;
47
        };
48
49
50
        /**
51
         * @public
52
         * @returns {Boolean}
53
         */
54
        this.isEditable = function() {
55
56
            return $element instanceof HTMLTextAreaElement || ($element instanceof HTMLInputElement && $element.type.toLowerCase() === 'text');
0 ignored issues
show
Bug introduced by
The variable HTMLInputElement seems to be never declared. If this is a global, consider adding a /** global: HTMLInputElement */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable HTMLTextAreaElement seems to be never declared. If this is a global, consider adding a /** global: HTMLTextAreaElement */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
57
        };
58
59
60
        /**
61
         * @public
62
         */
63
        this.hide = function() {
64
            $element.style.display = 'none';
65
        };
66
67
68
        /**
69
         * @public
70
         */
71
        this.show = function() {
72
            $element.style.display = '';
73
        };
74
    };
75
76
    return JsonGeneratorInput;
77
});